#include <iostream>
#include <string>
#include <cmath>
using namespace std;

int main() {
    string hex_num;
    int dec_num = 0;
    cin >> hex_num;
    for (int i = 0; i < hex_num.size(); i++) {
        char c = hex_num[i];
        int digit;
        if (c >= '0' && c <= '9') {
            digit = c - '0';
        }
        else if (c >= 'A' && c <= 'F') {
            digit = c - 'A' + 10;
        }
        else if (c >= 'a' && c <= 'f') {
            digit = c - 'a' + 10;
        }
        else {
            return 1;
        }
        dec_num += digit * pow(16, hex_num.size() - i - 1);
    }
    cout << dec_num << endl;
    return 0;
}